<template>
	<view class="container">
		<!-- 信息简介 -->
		<view class="profile">
			<!-- <image class="icon" src="/static/home-image/my_bg@3x.png"></image> -->
			<view class="desc">
				<view class="left avatar">
					<image v-if="photoUrl" :src="photoUrl" ></image>
					<i v-else class=" iconfont icon-jurassic_user f-40"></i>
				</view>
				<view class="right">
					<view class="name">{{name}}</view>
					<view class="phone">学号：{{number?number:'-'}}</view>
					<view class="phone">班级：{{className}}</view>
				</view>
			</view>
		</view>

		<view class="list">
			<view class="item" @click="navTo('/pages/password/password')">
				<view class="left">
					<image class="icon" src="../../static/images/edit.png"></image>
					<view class="txt">修改密码</view>
				</view>
				<i class="iconfont icon-gengduo f-15"></i>
			</view>
		</view>
		<view class="list">
			<view class="item" @click="showModel">
				<view class="left">
					<image class="icon" src="../../static/images/exit.png"></image>
					<view class="txt">退出登录</view>
				</view>
			</view>
		</view>
		<view class="model" v-if="isShow">
			<view class="btn" @click="logout(1)">关闭系统</view>
			<view class="btn" @click="logout(2)">退出登录</view>
			<view class="divider"></view>
			<view class="btn" @click="closeModel">取消</view>
		</view>
		<vide class="mask" v-if="isShow"></vide>
	</view>
</template>
<script>
	const api = require('@/utils/api.js');
	const util = require("@/utils/util.js")
	export default {
		data() {
			return {
				user: {},
				photoUrl: null,
				hasDiscern: false,
				isShow:false,
				name:"",
				number:"",
				className:'',
				result:'',//获取到的二维码内容，根据自己需求处理结果
				judgeObj: util.judgeObj(),
			};
		},
		methods: {
			showModel() {
				this.isShow = true
			},
			closeModel() {
				this.isShow = false
			},
			//跳转 type=0 跳转到个人中心
			navTo(url,type) {
				if (type === 0) {
					let user = uni.getStorageSync("user");
					let userId = null;
					if (user.userType === 0 && user.teacher !=null) { // 教师
						userId = user.teacher.id;
					} else if(user.userType === 1 && user.student != null) { // 学生
						userId = user.student.id;
					}
					uni.navigateTo({
						url: url +'?id=' + userId + '&type=' + user.userType
					})
				} else {
					uni.navigateTo({
						url: url
					})
				}
			},

			// 退出登录
			logout(value) {
				let label = value == 1?"关闭系统":"退出登录"
				util.modal("提示", "是否" + label, true, confirm => {
					if (confirm) {
						uni.removeStorageSync("token")
						uni.removeStorageSync("name")
						uni.removeStorageSync("phone")
						uni.removeStorageSync("menus")
						uni.removeStorage({
							key: "user",
							success() {
								// if(value == 1) {
								// 	location.href = util.judgeObj().loginPage
								// } else {
									uni.reLaunch({
										url:'/pages/login/login?token=xzl159357'
									})
								// }
							}
						})
					}
				})
			}
		},
		onShow() {
			//用户信息
			this.name=uni.getStorageSync("name")
			let users = uni.getStorageSync("user");
			this.className = users.student.className
			this.number = users.student.number
			if (users.photo != null) {
				this.photoUrl = util.commonUrl() + api.linkloadUrl + users.photo.moduleName + '/' + users.photo.fileNewName;
			}
		}
	}
</script>

<style lang="scss">
	.profile {
		position: relative;
		height: 300rpx;
		background: url('@/static/images/mine_bg.png');
		background-size: 100% 100%;
	}

	.profile .icon {
		position: absolute;
		top: 0;
		height: 400rpx;
		width: 100%;
	}

	.desc {
		width: 100%;
		display: flex;
		height: 300rpx;
		align-items: center;
		z-index: 999;
		top: 0;
		margin:0 30rpx;
		position: absolute;
	}
	.desc .left {
		margin-right:30rpx;
	}
	.desc .right {
		width:65%;
		vertical-align: middle;
	}
	
	.logout {
		width: 95%;
		color: #ffffff;
		margin:60rpx auto;
		font-size: 30rpx;
		margin-top:100px;
	}

	.avatar {
		position:relative;
		background-color: #e5e5e5;
		width: 200rpx;
		height: 200rpx;
		border-radius: 126rpx;
		color: #ffffffff;
	}
	.avatar image {
		width:100%;
		height:100%;
	}
	.avatar .iconfont {
		position: absolute;
		left: 50%;
		top:50%;
		transform: translate(-50%,-50%);
	}
	

	.name {
		font-size: 46rpx;
		color: #fff;
		margin-top: 18rpx;
	}

	.phone {
		font-size: 30rpx;
		color: #fff;
		margin-top: 18rpx;
	}
	.list {
		width:96%;
		margin:20px auto;
		border-radius: 20rpx;
		background-color: #ffffff;
		box-shadow: 2px 2px 3px #888888
	}
	.item {
		height: 110rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		padding-left: 40rpx;
		padding-right: 20rpx;
		align-items: center;
	}

	.item .left {
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.item .left .icon {
		width: 50rpx;
		height: 50rpx;
	}

	.left .txt {
		font-size: 30rpx;
		color: #262626;
		margin-left: 40rpx;
	}

	.item .icon {
		width: 16rpx;
		height: 28rpx;
	}

	.item .right {
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	
	.item .right .txt {
		font-size: 24rpx;
		color: $theme-red-color;
		margin-right: 20rpx;
	}

	.item .right .has_discern {
		color: #0369D6;
	}

	.item .right .icon {
		width: 16rpx;
		height: 28rpx;
	}

	.divider {
		background-color: #bfbfc7;
		height: 6rpx;
	}
	.model {
		position: fixed;
		bottom: 0;
		width:100%;
		border-top-left-radius: 20px;
		border-top-right-radius: 20px;
		z-index:999;
		background-color: #fff;
	}
	.btn {
		text-align: center;
		color: #444447;
		font-size:18px;
		margin:20rpx;
	}
</style>
